package com.njym.java.security.app.biz;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.njym.java.annotation.Cache;
import com.njym.java.security.app.entity.CourseSection;
import com.njym.java.security.app.entity.CourseSectionVo;
import com.njym.java.security.app.mapper.CourseSectionMapper;
import com.njym.java.security.common.biz.BaseBiz;
import com.njym.java.security.common.msg.TableResultResponse;
import com.njym.java.security.common.util.Query;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author Mr.AG
 * @email 463540703@qq.com
 * @date 2019-11-07 16:46:27
 */
@Service
public class CourseSectionBiz extends BaseBiz<CourseSectionMapper, CourseSection> {
	@Override
	public TableResultResponse<CourseSection> selectByQuery(Query query) {
		Example example = new Example(CourseSection.class);
		if(query.entrySet().size()>0) {
			Example.Criteria criteria = example.createCriteria();
			for (Map.Entry<String, Object> entry : query.entrySet()) {
				criteria.andLike(entry.getKey(), "%" + entry.getValue().toString() + "%");
			}
		}
		example.orderBy("sectionOrder");
		Page<Object> result = PageHelper.startPage(query.getPage(), query.getLimit());
		List<CourseSection> list = mapper.selectByExample(example);
		return new TableResultResponse<CourseSection>(result.getTotal(), list);
	}

	@Cache(key = "select_365",expire = 2)
    public List<CourseSection> select_365() {
		return mapper.select_365();
    }

//	@Cache(key = "selectFrees:{1}",expire = 2)
	public List<CourseSection> selectFrees(String classId) {
		return mapper.selectFrees(Integer.parseInt(classId));
	}

	@Cache(key = "get_freeSections:{1}",expire = 2)
	public List<CourseSection> get_freeSections(Integer classId) {
		return mapper.get_freeSections(classId);
	}

	@Cache(key = "get_sectionsByCouid:{1}",expire = 2)
	public List<CourseSection> get_sectionsByCouid(Integer couId) {
		return mapper.get_sectionsByCouid(couId);
	}

//	@Cache(key = "get_5_freeSections")
	public List<CourseSectionVo> get_5_freeSections() {
		return mapper.get_5_freeSections();
	}

	public List<CourseSectionVo> selectAllFree(Integer classId) {
		return mapper.selectAllFree(classId);
	}

	public List<CourseSection> get_sectionsByClassId(Integer classId) {
		return mapper.get_sectionsByClassId(classId);
	}

	@Cache(key = "getFreeSectionsByclassId:{1}",expire = 2)
	public List<CourseSection> get_2_FreeSections_ByclassId(Integer classId) {
		return mapper.get_2_FreeSections_ByclassId(classId);
	}


	public List<CourseSection> select_jyly_haveGotten(Integer userId, Integer courseId) {
		return mapper.select_jyly_haveGotten(userId, courseId);
	}

	public List<CourseSection> select_jyly_neverGotten(Integer userId, Integer courseId) {
		return mapper.select_jyly_neverGotten(userId, courseId);
	}

	public List<CourseSection> select_AiTing(Integer courseId) {
		return mapper.select_AiTing(courseId);
	}


	public CourseSection codeBycou(int couId) {
		return mapper.codeBycou(couId);
	}

	public void updatePlayTimes(Integer id, Integer times) {
		mapper.updatePlayTimes(id, times);
	}
}